package hikvision.controller;


import com.hikvision.anno.RedisLimit;

import hikvision.pojo.dto.LoginParam;
import hikvision.pojo.vo.LoginVo;
import hikvision.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Description TODO
 * @Author dongpengchao
 * @Version 1.0
 * @Date 2022/3/24 11:49
 * @see
 * @since 1.0
 */

@Controller
@RequestMapping("/demo")
public class MyController {
	@Autowired
	private UserService userService;

	/**
	 * 1 min 之内尝试超过5次, 锁定 user 1h
	 */
	@RedisLimit
	@RequestMapping(value = "/session", method = RequestMethod.POST)
	public ResponseEntity<LoginVo> login(@Validated @RequestBody LoginParam req) {
		return new ResponseEntity<>(userService.login(req), HttpStatus.OK);
	}
}
